package com.lhoverc.mapper;

import com.lhoverc.pojo.VO.AdminApplyVO;
import com.lhoverc.pojo.VO.ApplyDataVO;
import com.lhoverc.pojo.entity.ApplyEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: LiCheng
 * @CreateTime: 2025-04-16
 * @Description:
 * @Version: 1.0
 */
@Mapper
public interface ApplyMapper {
    /**
     * 获取申请信息
     *
     * @param visitorId
     * @param invitationCode
     * @return
     */
    @Select("select * from apply where visitor_id = #{visitorId} and invitation_code = #{invitationCode}")
    ApplyEntity getApply(Integer visitorId, String invitationCode);

    /**
     * 修改状态为到访以及添加图片置信度
     *
     * @param applyEntity
     */
    @Update("update apply set confidence = #{confidence}, state = 3")
    void updateStateToArrive(ApplyEntity applyEntity);

    @Select("select * from apply where user_id = #{id} and is_delete = 0")
    List<ApplyEntity> getApplyById(Integer id);

    /**
     * 批量更改申请状态
     *
     * @param ids
     * @param state
     */
    void updateState(List<Integer> ids, Integer state);

    /**
     * 获取ApplyData
     *
     * @param userId
     * @param state
     * @param startTime
     * @param endTime
     * @return
     */
    List<ApplyEntity> getApplyData(Integer userId, Integer state, LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 获取当天所有的申请
     *
     * @return
     */
    @Select("select * from apply where is_delete = 0 and #{today} between arrive_time and leave_time")
    List<ApplyDataVO> getAllTodayApply(LocalDateTime today);

    /**
     * 条件查询（所有用户申请）
     *
     * @param statusKeyword
     * @param startTime
     * @param endTime
     * @return
     */
    List<AdminApplyVO> getAllApply(String searchKeyword, Integer statusKeyword, LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 插入申请信息
     *
     * @param applyEntity
     */
    @Insert("insert into apply (user_id, visitor_id, destination, visitor_image, confidence, invitation_code, arrive_time, leave_time, to_do, state, create_time, update_time) VALUES " +
            "(#{userId}, #{visitorId}, #{destination}, #{visitorImage}, #{confidence}, #{invitationCode}, #{arriveTime}, #{leaveTime}, #{toDo}, #{state}, #{createTime}, #{updateTime})")
    void insertApply(ApplyEntity applyEntity);

    /**
     * 更新信息
     *
     * @param applyDataVO
     */
    @Update("update apply set destination = #{destination}, visitor_image = #{visitorImage}, to_do = #{toDo}, arrive_time = #{arriveTime}, leave_time = #{leaveTime} where id = #{id}")
    void updateApply(ApplyDataVO applyDataVO);

    /**
     * 批量删除信息
     *
     * @param ids
     */
    void delete(List<Integer> ids);

    @Select("select * from apply where is_delete = 0")
    List<ApplyEntity> getApplyNoParams();
}
